package com.cql.sys.handler;

import com.cql.pojo.Detials;
import com.cql.pojo.Dict;
import com.cql.sys.service.DictDetailService;
import com.cql.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description TODO
 * @Date 2025/6/18 11:14
 * @Created by 12336
 */

@RestController
@RequestMapping("/dictDetail")
public class DictDetailController {
    @Autowired
    private DictDetailService dictDetailService;

    @PostMapping("/add")
    public CommonResult addDictDetail(@RequestBody Detials dictDetail){
        if(dictDetail == null){
            return CommonResult.error(400,"请求参数不能为空");
        }
        int result = dictDetailService.addDictDetail(dictDetail);
        return CommonResult.success(result);

    }

    @PostMapping("/findAllDetails")
    public CommonResult<List<Detials>> findAllDetails(@RequestBody Dict dict){

        try {
            System.out.println( "@@@@"+dict);
            List<Detials> details = dictDetailService.findAllDetails(dict);
            if (null == details){
                return CommonResult.error(500, "未找到该字典");
            }

            return CommonResult.success(details);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.error(503, "系统异常,请联系管理员");
        }
    }


}
